package com.deyuanyun.pic.settings.support.validateFunc;

import com.deyuanyun.pic.common.validator.vinterface.ValidateInterface;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.deyuanyun.pic.common.spring.SpringAppliction;
import com.deyuanyun.pic.common.util.ObjectUtil;
import com.deyuanyun.pic.common.validator.vinterface.ValidateInterface;
import com.deyuanyun.pic.settings.domain.org.OrgInfo;
import com.deyuanyun.pic.settings.mapper.prvlg.UserMapper;

public class DepartmentValidata implements ValidateInterface {

	@Override
	public <T, E, C> boolean apply(T t, E e, C c) {
		OrgInfo company = null;
		List<OrgInfo> department = null;
		StringBuffer sb = new StringBuffer();
		if (ObjectUtil.isNotNullEmpty(t)) {
//			department = TempStoreDataSupport.pullDataf("tt_department");
//			if (ObjectUtil.isEmptyAll(department)) {
				try {
					String companyName = BeanUtils.getProperty(c, "company");
					UserMapper um = SpringAppliction.getBean(UserMapper.class);
					company = um.selectCompanyByCompanyName(companyName);
					department = um.selectDepartmentByCompanyId(null == company.getId() ? "":company.getId());
					for (OrgInfo org : department) {
						if (ObjectUtil.isNotNullEmpty(org)) {
							sb.append(org.getName()).append(",");
						}
					}
				} catch (Exception e1) {
					e1.printStackTrace();
				}
//				TempStoreDataSupport.pushDataf("tt_department", department);
//			}
		}
		return sb.toString().contains(t.toString());
	}

	@Override
	public String getName() {
		return null;
	}

}
